//
//  main.m
//  TempTest
//
//  Created by yao zhaofeng on 2018/4/2.
//  Copyright © 2018年 YaoZhaofeng. All rights reserved.
//

//#import <Foundation/Foundation.h>

#include <exception>
#include <iostream>
using namespace std;

//#include "code_convert.hpp"
void TestIntType()
{
    try
    {
        throw 1;
    }
    catch(...)
    {
        cout<< "在 try block 中, 准备抛出一个异常." << endl;
    }
}

void TestDoubleType()
{
    try
    {
        throw 0.5;
    }
    catch(...)
    {
        cout<< "在 try block 中, 准备抛出一个异常." << endl;
    }
}

void TestEmptyPointType()
{
    try
    {
        int* p = NULL;
        *p = 3;
    }
    catch(...)
    {
        cout<< "非法地址操作异常" << endl;
    }
}

void TestDivZeroType()
{
    try
    {
        int b = 0;
        int a = 3/b;
    }
    catch(...)
    {
        cout<< "0除异常" << endl;
    }
}

void TestMemoryOutType()
{
    int * a = new int[4];
    try
    {
        for (int i = 0; i<245; i++)
        {
            a++;
        }
        *a = 3;
    }
    catch(...)
    {
        cout<< "内存越界异常" << endl;
    }
}

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        
        // insert code here...
//        NSLog(@"Hello, World!");
//        int arrayName[4] = {10, 20, 30, 40};
//        int *p = (int *)(&arrayName +1);
//        NSLog(@"%d", *(p-1));
//        int a = 0;
//        int b = a>0?:1;
//
//        NSLog(@"b is %d", b);
        
        TestEmptyPointType();
        //TestDivZeroType();
        TestMemoryOutType();
        return 1;

    }
    return 0;
}
